popovermenu: Avoid a critical
authorMatthias Clasen <mclasen@redhat.com>
Sun, 2 Aug 2020 17:09:00 +0000 (13:09 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 2 Aug 2020 17:09:00 +0000 (13:09 -0400)
While we guarantee that the widget that a controller
is attached to stays around while it is handling an event,
the same is not true for the root that the widget belongs
to. In corner cases (such as clicking "Close" in the
fallback window menu), it may already be gone.
Avoid a critical in that case.

Fixes: #2998
gtk/gtkpopovermenu.c

index 2108f1553521869c3bdd081370884701be0dd665..707429c730f4d3b7b15d0bc91dbf1655147e2aa1 100644 (file)
@@ -228,7 +228,14 @@ static void
 focus_out (GtkEventController   *controller,
            GtkPopoverMenu       *menu)
 {
-  GtkWidget *new_focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (menu)));
+  GtkRoot *root;
+  GtkWidget *new_focus;
+
+  root = gtk_widget_get_root (GTK_WIDGET (menu));
+  if (!root)
+    return;
+
+  new_focus = gtk_root_get_focus (root);
 
   if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller)) &&
       new_focus != NULL)